package com.sicent.operate.common.util;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class CookieUtils {
	
	
	public static String LONG_COOKIE="operatesignature";
	
	/**
	 * 设置cookie
	 * @param response
	 * @param key
	 * @param name
	 */
	public static void setCookie(HttpServletResponse response,String name,String value){
	     Cookie cookie=new Cookie(name, value);
	     cookie.setPath("/");
	     cookie.setMaxAge(-1);
	     response.addCookie(cookie);
	}

	/**
	 * 获取cookie的值
	 * @param request
	 * @param name
	 * @return
	 */
	public static String getCookie(HttpServletRequest request,String name){
		String cookieStr=null;
	    Cookie[] cookies = request.getCookies();
	    if(null!=cookies){
	        for(Cookie cookie : cookies){
	          if(name.equals(cookie.getName())){
	        	  cookieStr= cookie.getValue();
	        	  return cookieStr;
	          }
	        }
	    }
	    return cookieStr;
	}
}
